package com.gdpu.project.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.gdpu.page.vo.QueryResult;
import com.gdpu.project.dao.CgConferenceDao;
import com.gdpu.project.dao.CgInnovateDao;
import com.gdpu.project.dao.CgPatentDao;
import com.gdpu.project.dao.CgProjectDao;
import com.gdpu.project.dao.CgThesisDao;
import com.gdpu.project.dao.CgTreatiseDao;
import com.gdpu.project.dao.TeacherDao;
import com.gdpu.project.service.ChengGuoService;
import com.gdpu.project.vo.CgConference;
import com.gdpu.project.vo.CgInnovate;
import com.gdpu.project.vo.CgPatent;
import com.gdpu.project.vo.CgProject;
import com.gdpu.project.vo.CgThesis;
import com.gdpu.project.vo.CgTreatise;
import com.gdpu.project.vo.Teacher;

public class ChengGuoServiceImpl implements ChengGuoService {
	private CgConferenceDao cgConferenceDao;
	private CgInnovateDao cgInnovateDao;
	private CgPatentDao cgPatentDao;
	private CgThesisDao cgThesisDao;
	private CgTreatiseDao cgTreatiseDao;
	private TeacherDao teacherDao;
	private CgProjectDao cgProjectDao;

	public CgConferenceDao getCgConferenceDao() {
		return cgConferenceDao;
	}

	public void setCgConferenceDao(CgConferenceDao cgConferenceDao) {
		this.cgConferenceDao = cgConferenceDao;
	}

	public CgInnovateDao getCgInnovateDao() {
		return cgInnovateDao;
	}

	public void setCgInnovateDao(CgInnovateDao cgInnovateDao) {
		this.cgInnovateDao = cgInnovateDao;
	}

	public CgPatentDao getCgPatentDao() {
		return cgPatentDao;
	}

	public void setCgPatentDao(CgPatentDao cgPatentDao) {
		this.cgPatentDao = cgPatentDao;
	}

	public CgThesisDao getCgThesisDao() {
		return cgThesisDao;
	}

	public void setCgThesisDao(CgThesisDao cgThesisDao) {
		this.cgThesisDao = cgThesisDao;
	}

	public CgTreatiseDao getCgTreatiseDao() {
		return cgTreatiseDao;
	}

	public void setCgTreatiseDao(CgTreatiseDao cgTreatiseDao) {
		this.cgTreatiseDao = cgTreatiseDao;
	}

	public TeacherDao getTeacherDao() {
		return teacherDao;
	}

	public void setTeacherDao(TeacherDao teacherDao) {
		this.teacherDao = teacherDao;
	}
	

	public CgProjectDao getCgProjectDao() {
		return cgProjectDao;
	}

	public void setCgProjectDao(CgProjectDao cgProjectDao) {
		this.cgProjectDao = cgProjectDao;
	}

	public Boolean addCgConference(CgConference cgConference) {
		if(cgConference!=null){
		cgConferenceDao.save(cgConference);
		return true;
		}
		return false;
	}

	public Boolean addCgInnovate(CgInnovate cgInnovate) {
		if(cgInnovate!=null){
			cgInnovateDao.save(cgInnovate);
			return true;
			}
			return false;
	}

	public Boolean addCgPatent(CgPatent cgPatent) {
		if(cgPatent!=null){
			cgPatentDao.save(cgPatent);
			return true;
			}
			return false;
	}

	public Boolean addCgThesis(CgThesis cgThesis) {
		if(cgThesis!=null){
			cgThesisDao.save(cgThesis);
			return true;
			}
			return false;
	}

	public Boolean addCgTreatise(CgTreatise cgTreatise) {
		if(cgTreatise!=null){
			cgTreatiseDao.save(cgTreatise);
			return true;
		}
		return null;
	}


	public QueryResult<CgConference> findAllCgConference(int firstindex,int maxresult) {
		QueryResult<CgConference> queryResult = cgConferenceDao.findAll(firstindex,maxresult);
			return queryResult;
		
	}

	public QueryResult<CgConference> findAllCgConferenceByTeacherId(String teacherId,int firstindex,int maxresult) {
		QueryResult<CgConference> queryResult = cgConferenceDao.findByTeacherId(teacherId,firstindex,maxresult);		
			return queryResult;		
	}

	public QueryResult<CgInnovate> findAllCgInnovate(int firstindex,int maxresult) {
		QueryResult<CgInnovate> queryResult = cgInnovateDao.findAll(firstindex,maxresult);
			return queryResult;
	
	}

	public QueryResult<CgInnovate> findAllCgInnovateByTeacherId(String teacherId,int firstindex,int maxresult) {
		QueryResult<CgInnovate> queryResult = cgInnovateDao.findByTeacherId(teacherId,firstindex,maxresult);
			return queryResult;
	}
	public QueryResult<CgInnovate> findAllCgInnovateByTeacherId(String teacherId) {
		QueryResult<CgInnovate> queryResult = cgInnovateDao.findByTeacherId(teacherId);
		return queryResult;
	}

	public QueryResult<CgPatent> findAllCgPatent(int firstindex,int maxresult) {
		QueryResult<CgPatent> queryResult = cgPatentDao.findAll(firstindex,maxresult);
			return queryResult;
	}

	public QueryResult<CgPatent> findAllCgPatentByTeacherId(String teacherId,int firstindex,int maxresult) {
		QueryResult<CgPatent> queryReslut =cgPatentDao.findByTeacherId(teacherId,firstindex,maxresult);
			return queryReslut;
		
	}

	public QueryResult<CgThesis> findAllCgThesis(int firstindex,int maxresult) {
		QueryResult<CgThesis> qRcgThesis =cgThesisDao.findAll(firstindex,maxresult);
		if(qRcgThesis!=null){
			return qRcgThesis;
		}
		return null;
	}

	public  QueryResult<CgThesis> findAllCgThesisByTeacherId(String teacherId,int firstindex,int maxresult) {
		 QueryResult<CgThesis> qRcgThesis =cgThesisDao.findByTeacherId(teacherId,firstindex,maxresult);

		 if(qRcgThesis!=null){
				return qRcgThesis ;
		 }
		return null;
	}
	public QueryResult<CgThesis> findAllCgThesisByTeacherId(String teacherId) {
		return findAllCgThesisByTeacherId(teacherId,-1,-1);
	}

	public QueryResult<CgTreatise> findAllCgTreatise(int firstindex,int maxresult) {
		QueryResult<CgTreatise> queryResult =cgTreatiseDao.findAll(firstindex,maxresult);
			return queryResult;
	}

	public QueryResult<CgTreatise> findAllCgTreatiseByTeacherId(String teacherId,int firstindex,int maxresult) {
		QueryResult<CgTreatise> queryResult=cgTreatiseDao.findByTeacherId(teacherId, firstindex, maxresult);
			return queryResult;
	}

	public Boolean updateCgConference(CgConference cgConference) {
		if(cgConference!=null){
			cgConferenceDao.merge(cgConference);
			return true;
		}
		return false;
	}

	public Boolean updateCgInnovate(CgInnovate cgInnovate) {
		if(cgInnovate!=null){
			cgInnovateDao.merge(cgInnovate);
			return true;
		}
		return false;
	}

	public Boolean updateCgPatent(CgPatent cgPatent) {
		if(cgPatent!=null){
			cgPatentDao.merge(cgPatent);
			return true;
		}
		return false;
	}

	public Boolean updateCgThesis(CgThesis cgThesis) {
		if(cgThesis!=null){
			cgThesisDao.merge(cgThesis);
			return true;
		}
		return false;
	}

	public Boolean updateCgTreatise(CgTreatise cgTreatise) {
		if(cgTreatise!=null){
			cgTreatiseDao.merge(cgTreatise);
			return true;
		}
		return false;
	}

	public Boolean deleteCgConferenceById(int id) {
		CgConference cgConference = cgConferenceDao.findById(id);
		if(cgConference!=null){
			cgConferenceDao.delete(cgConference);
			return true;
		}
		return false;
	}

	public Boolean deleteCgInnovateById(int id) {
		CgInnovate cgInnovate = cgInnovateDao.findById(id);
		if(cgInnovate!=null){
			cgInnovateDao.delete(cgInnovate);
			return true;
		}
		return false;
	}

	public Boolean deleteCgPatentById(int id) {
		CgPatent cgPatent = cgPatentDao.findById(id);
		if(cgPatent!=null){
			cgPatentDao.delete(cgPatent);
			return true;
		}
		return false;
	}

	public Boolean deleteCgThesisById(int id) {
		CgThesis cgThesis = cgThesisDao.findById(id);
		if(cgThesis!=null){
			cgThesisDao.delete(cgThesis);
			return true;
		}
		return false;
	}

	public Boolean deleteCgTreatiseById(int id) {
		CgTreatise cgTreatise = cgTreatiseDao.findById(id);
		if(cgTreatise!=null){
			cgTreatiseDao.delete(cgTreatise);
			return true;
		}
		return false;
	}

	public CgConference findCgConference(int id) {
		CgConference cgConference = cgConferenceDao.findById(id);
			return cgConference;
	}

	public CgInnovate findCgInnovate(int id) {
		CgInnovate cgInnovate = cgInnovateDao.findById(id);
		return cgInnovate;
	}

	public CgPatent findCgPatent(int id) {
		CgPatent cgPatent = cgPatentDao.findById(id);
		return cgPatent;
	}

	public CgThesis findCgThesis(int id) {
		CgThesis cgThesis = cgThesisDao.findById(id);
		return cgThesis;
	}

	public CgTreatise findCgTreatise(int id) {
		CgTreatise cgTreatise = cgTreatiseDao.findById(id);
		return cgTreatise;
	}

	public Boolean addCgProject(CgProject cgProject) {
		if(cgProject!=null){
			cgProjectDao.save(cgProject);
			return true;
		}
		return false;
	}

	public Boolean deleteCgProjectById(int id) {
		CgProject cgProject = cgProjectDao.findById(id);
		if(cgProject!=null){
			cgProjectDao.delete(cgProject);
			return true;
		}
		return false;
	}

	public QueryResult<CgProject> findAllCgProject(int firstindex,int maxresult) {
		QueryResult<CgProject> list = cgProjectDao.findAll(firstindex,maxresult);
			return list;
	}

	public QueryResult<CgProject> findAllCgProjectByTeacherId(String teacherId,int firstindex,int maxresult) {
		QueryResult<CgProject> QueryResult = cgProjectDao.findByTeacherId(teacherId, firstindex, maxresult);
		
			return QueryResult;
	}

	public CgProject findCgProject(int id) {
		CgProject cgProject = cgProjectDao.findById(id);
		if(cgProject!=null){
			return cgProject;
		}
		return null;
	}

	public Boolean updateCgProject(CgProject cgProject) {
		if(cgProject!=null){
			cgProjectDao.merge(cgProject);
			return true;
		}
		return false;
	}

	public Map<Teacher,List<CgProject>> searchCgProject(String college,
			String department, String postion, String education,
			String teacherId,String cataloge) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education,cataloge, teacherId);
		Map<Teacher,List<CgProject>> map = new HashMap<Teacher, List<CgProject>>();
		if(teacherlist.size()>0){
			 Iterator<Teacher> it = teacherlist.iterator();   
		        while (it.hasNext())   
		        {   
		               Teacher teacher = it.next();
		               String Id = teacher.getTeacherId();
		               QueryResult<CgProject> queryResult = cgProjectDao.findByTeacherId(Id );
		               List<CgProject> list= new ArrayList<CgProject>();
		               if(queryResult.getTotalrecord()>0){
		            	   Iterator<CgProject> it1 = queryResult.getResultlist().iterator();
		            	   while (it1.hasNext()){   
		            		   CgProject cgProject = it1.next();
		            		   list.add(cgProject);
		            	   }
		               }
		               map.put(teacher, list);
		        }
		}
		 return map;
	}
	
	
	public Map<Teacher,List<CgProject>> searchCgProjectByDate(String college,
			String department, String postion, String education,
			String teacherId,String cataloge,Date startDate,Date endDate) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education,cataloge, teacherId);
		Map<Teacher,List<CgProject>> map = new HashMap<Teacher, List<CgProject>>();
		if(teacherlist.size()>0){
			 Iterator<Teacher> it = teacherlist.iterator();   
		        while (it.hasNext())   
		        {
		               Teacher teacher = it.next();
		               String Id = teacher.getTeacherId();
		               List<CgProject> cgProjectlist = cgProjectDao.nfindByProperty("teacherId", Id, startDate, endDate);
		               List<CgProject> list=new ArrayList<CgProject>();
		               if(cgProjectlist.size()>0){
		            	   Iterator<CgProject> it1 = cgProjectlist.iterator();
		            	   while (it1.hasNext()){   
		            		   CgProject cgProject = it1.next();
		            		   list.add(cgProject);
		            	   }
		               }
		               map.put(teacher,list);
		        }
		}
		  return map;
	}
	/**
	 * 项目分页查询
	 */
	public QueryResult<CgProject> searchCgProjectByDate(String college,
			String department, String postion, String education,
			String teacherId,String cataloge,Date startDate,Date endDate,int firstindex,int maxresult) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education,cataloge, teacherId);
		List<String> teacherIdList=new ArrayList<String>();
		for(Teacher teacher:teacherlist){
			teacherIdList.add(teacher.getTeacherId());
		}
		QueryResult<CgProject> queryResult = cgProjectDao.nfindByProperty("teacherId", teacherIdList, startDate, endDate, firstindex, maxresult);
				
		return queryResult;
	}

	public Map<Teacher,List<CgConference>> searchCgConferenceByDate(String college,
			String department, String postion, String education,
			String teacherId,String cataloge,Date startDate,Date endDate) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education, cataloge,teacherId);
		Map<Teacher,List<CgConference>> map = new HashMap<Teacher, List<CgConference>>();
		if(teacherlist.size()>0){
			 Iterator<Teacher> it = teacherlist.iterator();   
		        while (it.hasNext())   
		        {   
		               Teacher teacher = it.next();
		               String Id = teacher.getTeacherId();
		               List<CgConference> cgConferencelist = cgConferenceDao.nfindByProperty("teacherId", Id, startDate, endDate);
		               List<CgConference> list=new ArrayList<CgConference>();
		               if(cgConferencelist.size()>0){
		            	   Iterator<CgConference> it1 = cgConferencelist.iterator();   
		            	   while (it1.hasNext()){   
		            		   CgConference cgConference = it1.next();
		            			  list.add(cgConference);
		   		        	}
		               }
		               map.put(teacher, list);
		          }
		        }
		  return map;
	}
	
	/**
	 * 学术会议分页查询
	 */
	public QueryResult<CgConference> searchCgConferenceByDate(String college,
			String department, String postion, String education,
			String teacherId,String cataloge,Date startDate,Date endDate,int firstindex,int maxresult) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education,cataloge, teacherId);
		List<String> teacherIdList=new ArrayList<String>();
		for(Teacher teacher:teacherlist){
			teacherIdList.add(teacher.getTeacherId());
		}
		QueryResult<CgConference> queryResult = cgConferenceDao.nfindByProperty("teacherId", teacherIdList, startDate, endDate, firstindex, maxresult);
				
		return queryResult;
	}
	
	public Map<Teacher,List<CgConference>> searchCgConference(String college,
			String department, String postion, String education,
			String teacherId,String cataloge) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education,cataloge, teacherId);
		Map<Teacher,List<CgConference>> map = new HashMap<Teacher, List<CgConference>>();
		if(teacherlist.size()>0){
			 Iterator<Teacher> it = teacherlist.iterator();   
		        while (it.hasNext())   
		        {   
		               Teacher teacher = it.next();
		               String Id = teacher.getTeacherId();
		               QueryResult<CgConference> queryResult = cgConferenceDao.findByTeacherId(Id);
		               List<CgConference> list=new ArrayList<CgConference>();
		               if(queryResult.getTotalrecord()>0){
		            	   Iterator<CgConference> it1 = queryResult.getResultlist().iterator();   
		            	   while (it1.hasNext()){   
		            		   CgConference cgConference = it1.next();
		            		   list.add(cgConference);
		            	   }
		               }
		               map.put(teacher, list);
		        }
		}
		  return map;
	}

	public Map<Teacher,List<CgInnovate>> searchCgInnovate(String college,
			String department, String postion, String education,
			String teacherId,String cataloge) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education, cataloge,teacherId);
		Map<Teacher,List<CgInnovate>> map = new HashMap<Teacher, List<CgInnovate>>();
		if(teacherlist.size()>0){
			 Iterator<Teacher> it = teacherlist.iterator();   
		        while (it.hasNext())   
		        {   
		               Teacher teacher = it.next();
		               String Id = teacher.getTeacherId();
		               QueryResult<CgInnovate> queryResult = cgInnovateDao.findByTeacherId(Id);
		               List<CgInnovate> list = new ArrayList<CgInnovate>();
		               if(queryResult.getTotalrecord()>0){
		            	Iterator<CgInnovate> it1 = queryResult.getResultlist().iterator();   
		            	while (it1.hasNext()){   
		            		CgInnovate cgInnovate = it1.next();
		            		list.add(cgInnovate);
		               }
		             }
		             map.put(teacher, list);
		        }
		}
		 return map;
	}
	
	public Map<Teacher,List<CgInnovate>> searchCgInnovateByDate(String college,
			String department, String postion, String education,
			String teacherId,String cataloge,Date startDate,Date endDate) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education,cataloge, teacherId);
		Map<Teacher,List<CgInnovate>> map = new HashMap<Teacher, List<CgInnovate>>();
		if(teacherlist.size()>0){
			 Iterator<Teacher> it = teacherlist.iterator();   
		        while (it.hasNext())   
		        {   
		               Teacher teacher = it.next();
		               String Id = teacher.getTeacherId();
		               List<CgInnovate> cgInnovatelist = cgInnovateDao.nfindByProperty("teacherId", Id, startDate, endDate);
		               List<CgInnovate> list = new ArrayList<CgInnovate>();//这里直接指向cgInnovatelist不就行了？？？
		               if(cgInnovatelist.size()>0){
		            	   Iterator<CgInnovate> it1 = cgInnovatelist.iterator();   
		            	   while (it1.hasNext()){   
		            		   CgInnovate cgInnovate = it1.next();
		            			   list.add(cgInnovate);
		            	   }
		               }
		               map.put(teacher, list);
		        }
		}
		  return map;
	}
	
	/**
	 * 科技创新分页查询
	 */
	public QueryResult<CgInnovate> searchCgInnovateByDate(String college,
			String department, String postion, String education,
			String teacherId,String cataloge,Date startDate,Date endDate,int firstindex,int maxresult) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education,cataloge, teacherId);
		List<String> teacherIdList=new ArrayList<String>();
		for(Teacher teacher:teacherlist){
			teacherIdList.add(teacher.getTeacherId());
		}
		QueryResult<CgInnovate> queryResult = cgInnovateDao.nfindByProperty("teacherId", teacherIdList, startDate, endDate, firstindex, maxresult);
				
		return queryResult;
	}

	public Map<Teacher,List<CgPatent>> searchCgPatent(String college,
			String department, String postion, String education,
			String teacherId,String cataloge) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education,cataloge, teacherId);
		Map<Teacher,List<CgPatent>> map = new HashMap<Teacher, List<CgPatent>>();
		if(teacherlist.size()>0){
			 Iterator<Teacher> it = teacherlist.iterator();   
		        while (it.hasNext())   
		        {   
		               Teacher teacher = it.next();
		               String Id = teacher.getTeacherId();
		               QueryResult<CgPatent> queryResult = cgPatentDao.findByTeacherId(Id);
		               List<CgPatent> list = new ArrayList<CgPatent>();
		               if(queryResult.getTotalrecord()>0){
		            	   Iterator<CgPatent> it1 = queryResult.getResultlist().iterator();   
		            	   while (it1.hasNext()){   
		            		   CgPatent cgPatent = it1.next();
		            		   list.add(cgPatent);
		            	   }
		               }
		               map.put(teacher, list);
		        }
		}
		return map;
	}
	
	public Map<Teacher,List<CgPatent>> searchCgPatentByDate(String college,
			String department, String postion, String education,
			String teacherId,String cataloge,Date startDate,Date endDate) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education, cataloge,teacherId);
		Map<Teacher,List<CgPatent>> map = new HashMap<Teacher, List<CgPatent>>();
		if(teacherlist.size()>0){
			 Iterator<Teacher> it = teacherlist.iterator();   
		        while (it.hasNext())   
		        {   
		               Teacher teacher = it.next();
		               String Id = teacher.getTeacherId();
		               List<CgPatent> cgPatentlist = cgPatentDao.nfindByProperty("teacherId", Id, startDate, endDate);
		               List<CgPatent> list = new ArrayList<CgPatent>();
		               if(cgPatentlist.size()>0){
		            	   Iterator<CgPatent> it1 = cgPatentlist.iterator();   
		            	   while (it1.hasNext()){   
		            		   CgPatent cgPatent = it1.next();
		            			 list.add(cgPatent);
		            	   }
		               }
		               map.put(teacher, list);
		        }
		}
		  return map;
	}
	
	/**
	 * 专利分页查询
	 */
	public QueryResult<CgPatent> searchCgPatentByDate(String college,
			String department, String postion, String education,
			String teacherId,String cataloge,Date startDate,Date endDate,int firstindex,int maxresult) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education,cataloge, teacherId);
		List<String> teacherIdList=new ArrayList<String>();
		for(Teacher teacher:teacherlist){
			teacherIdList.add(teacher.getTeacherId());
		}
		QueryResult<CgPatent> queryResult = cgPatentDao.nfindByProperty("teacherId", teacherIdList, startDate, endDate, firstindex, maxresult);
				
		return queryResult;
	}
	
	public Map<Teacher,List<CgThesis>> searchCgThesis(String college,
			String department, String postion, String education,
			String teacherId,String cataloge) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education, cataloge,teacherId);
		Map<Teacher,List<CgThesis>> map = new HashMap<Teacher, List<CgThesis>>();
		if(teacherlist.size()>0){
			 Iterator<Teacher> it = teacherlist.iterator();   
		        while (it.hasNext())   
		        {   
		               Teacher teacher = it.next();
		               String Id = teacher.getTeacherId();
		               QueryResult<CgThesis> queryResult = cgThesisDao.findByTeacherId(Id);
		               List<CgThesis> list=new ArrayList<CgThesis>();
		               if(queryResult!=null){
		            	   Iterator<CgThesis> it1 = queryResult.getResultlist().iterator();   
		            	   while (it1.hasNext()){   
		            		   CgThesis cgThesis = it1.next();
		            		   list.add(cgThesis);
		            	   }
		               }
		               map.put(teacher, list);
		        }
		}
		  return map;
	}
	
	public Map<Teacher,List<CgThesis>> searchCgThesisByDate(String college,
			String department, String postion, String education,
			String teacherId,String cataloge,Date startDate,Date endDate) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education,cataloge, teacherId);
		Map<Teacher,List<CgThesis>> map = new HashMap<Teacher, List<CgThesis>>();
		if(teacherlist.size()>0){
			 Iterator<Teacher> it = teacherlist.iterator();   
		        while (it.hasNext())   
		        {   
		               Teacher teacher = it.next();
		               String Id = teacher.getTeacherId();
		               List<CgThesis> cgThesislist = cgThesisDao.nfindByProperty("teacherId", Id, startDate, endDate);
		               List<CgThesis> list= new ArrayList<CgThesis>();
		               if(cgThesislist.size()>0){
		            	   Iterator<CgThesis> it1 = cgThesislist.iterator();   
		            	   while (it1.hasNext()){   
		            		   CgThesis cgThesis = it1.next();
		            			  list.add(cgThesis);
		            	   }
		               }
		               map.put(teacher, list);
		        }
		}
		  return map;

	}
	/**
	 * 论文分页查询
	 */
	public QueryResult<CgThesis> searchCgThesisByDate(String college,
			String department, String postion, String education,
			String teacherId,String cataloge,Date startDate,Date endDate,int firstindex,int maxresult) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education,cataloge, teacherId);
		List<String> teacherIdList=new ArrayList<String>();
		for(Teacher teacher:teacherlist){
			teacherIdList.add(teacher.getTeacherId());
		}
		QueryResult<CgThesis> queryResult = cgThesisDao.nfindByProperty("teacherId", teacherIdList, startDate, endDate, firstindex, maxresult);
				
		return queryResult;
		
	}
	
	public Map<Teacher,List<CgTreatise>> searchCgTreatise(String college,
			String department, String postion, String education,
			String teacherId,String cataloge) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education,cataloge, teacherId);
		Map<Teacher,List<CgTreatise>> map = new HashMap<Teacher, List<CgTreatise>>();
		if(teacherlist.size()>0){
			 Iterator<Teacher> it = teacherlist.iterator();   
		        while (it.hasNext())   
		        {   
		               Teacher teacher = it.next();
		               String Id = teacher.getTeacherId();
		               QueryResult<CgTreatise> queryResult = cgTreatiseDao.findByTeacherId(Id);
		               List<CgTreatise> list=new ArrayList<CgTreatise>();
		               if(queryResult.getTotalrecord()>0){
		            	   Iterator<CgTreatise> it1 = queryResult.getResultlist().iterator();   
		            	   while (it1.hasNext()){   
		            		   CgTreatise cgTreatise = it1.next();
		            		   list.add(cgTreatise);
		            	   }
		               }
		               map.put(teacher, list);
		        }
		}
		  return map;
	}

	public Map<Teacher,List<CgTreatise>> searchCgTreatiseByDate(String college,
			String department, String postion, String education,
			String teacherId,String cataloge,Date startDate,Date endDate) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education,cataloge, teacherId);
		Map<Teacher,List<CgTreatise>> map = new HashMap<Teacher, List<CgTreatise>>();
		if(teacherlist.size()>0){
			 Iterator<Teacher> it = teacherlist.iterator();   
		        while (it.hasNext())   
		        {   
		               Teacher teacher = it.next();
		               String Id = teacher.getTeacherId();
		               List<CgTreatise> cgTreatiselist = cgTreatiseDao.nfindByProperty("teacherId", Id, startDate, endDate);
		               List<CgTreatise> list=new ArrayList<CgTreatise>();
		               if(cgTreatiselist.size()>0){
		            	   Iterator<CgTreatise> it1 = cgTreatiselist.iterator();   
		            	   while (it1.hasNext()){   
		            		   CgTreatise cgTreatise = it1.next();
		            			   list.add(cgTreatise);
		            	   }
		               }
		               map.put(teacher, list);
		        }
		}
		  return map;
	}
	/**
	 * 专著分页查询
	 * @param college
	 * @param department
	 * @param postion
	 * @param education
	 * @param teacherId
	 * @param cataloge
	 * @param startDate
	 * @param endDate
	 * @param firstindex
	 * @param maxresult
	 * @return
	 */
	public QueryResult<CgTreatise> searchCgTreatiseByDate(String college,
			String department, String postion, String education,
			String teacherId,String cataloge,Date startDate,Date endDate,int firstindex,int maxresult) {
		List<Teacher> teacherlist = teacherDao.searchTeacher(college, department, postion, education,cataloge, teacherId);
		List<String> teacherIdList=new ArrayList<String>();
		for(Teacher teacher:teacherlist){
			teacherIdList.add(teacher.getTeacherId());
		}
		QueryResult<CgTreatise> queryResult = cgTreatiseDao.nfindByProperty("teacherId", teacherIdList, startDate, endDate, firstindex, maxresult);
				
		return queryResult;
	}
	public Map<String, String> analyse(String s,String s2) {
		Map<String, String> map = new HashMap<String, String>();
		List<String> list = new ArrayList<String>();
		if(s.equals("department")){
			list = teacherDao.findDistinctByDepartment();
		for(int i=0;i<list.size();i++){
			String s1 = list.get(i);
			int count1 = 0;
			int count2 = 0;
			if(s1!=null&&!"".equals(s1)){
				List<Teacher> teacherlist = teacherDao.findByDepartment(s1);
				if(teacherlist.size()>0){
					 Iterator<Teacher> it = teacherlist.iterator();   
				        while (it.hasNext())   
				        {   
				               Teacher teacher = it.next();
				               String teacherId = teacher.getTeacherId();
				               if(s2.equals("CgProject")){
				            	   QueryResult<CgProject> queryResult = cgProjectDao.findByTeacherId(teacherId);
				            	   count1 = (int)queryResult.getTotalrecord();
				               } 
				               if(s2.equals("CgConference")){
				            	   QueryResult<CgConference> queryResult = cgConferenceDao.findByTeacherId(teacherId);
				            	   count1 = (int)queryResult.getTotalrecord();
				               } 
				               if(s2.equals("CgInnovate")){
				            	   QueryResult<CgInnovate> queryResult = cgInnovateDao.findByTeacherId(teacherId);
				            	   count1 = (int)queryResult.getTotalrecord();
				               } 
				               if(s2.equals("CgPatent")){
				            	   QueryResult<CgPatent> queryResult = cgPatentDao.findByTeacherId(teacherId);
				            	   count1 = (int)queryResult.getTotalrecord();
				               } 
				               if(s2.equals("CgThesis")){
				            	   QueryResult<CgThesis> queryResult = cgThesisDao.findByTeacherId(teacherId);
				            	   count1 = (int) queryResult.getTotalrecord();
				               } 
				               if(s2.equals("CgTreatise")){
				            	   QueryResult<CgTreatise> queryResult = cgTreatiseDao.findByTeacherId(teacherId);
				            	   count1 = (int)queryResult.getTotalrecord();
				               } 
				               count2 =count2+count1;
				               
				               
				          }
				     }
				  String s3 =""+count2;
				  map.put(s1,s3);
				}
			}
		}
		if(s.equals("education")){
			list = teacherDao.findDistinctByEducation();
		for(int i=0;i<list.size();i++){
			String s1 = list.get(i);
			int count1 = 0;
			int count2 = 0;
			if(s1!=null){
				List<Teacher> teacherlist = teacherDao.findByEducation(s1);
				if(teacherlist.size()>0){
					 Iterator<Teacher> it = teacherlist.iterator();   
				        while (it.hasNext())   
				        {   
				               Teacher teacher = it.next();
				               String teacherId = teacher.getTeacherId();
				               if(s2.equals("CgProject")){
				            	   QueryResult<CgProject> queryResult = cgProjectDao.findByTeacherId(teacherId);
				            	   count1 = (int)queryResult.getTotalrecord();
				               } 
				               if(s2.equals("CgConference")){
				            	   QueryResult<CgConference> queryResult = cgConferenceDao.findByTeacherId(teacherId);
				            	   count1 = (int)queryResult.getTotalrecord();
				               } 
				               if(s2.equals("CgInnovate")){
				               	   QueryResult<CgInnovate> queryResult = cgInnovateDao.findByTeacherId(teacherId);
				            	   count1 = (int)queryResult.getTotalrecord();
				               } 
				               if(s2.equals("CgPatent")){
				            	   QueryResult<CgPatent> queryResult = cgPatentDao.findByTeacherId(teacherId);
				            	   count1 = (int)queryResult.getTotalrecord();
				               } 
				               if(s2.equals("CgThesis")){
				            	   QueryResult<CgThesis> queryResult = cgThesisDao.findByTeacherId(teacherId);
				            	   count1 = (int)queryResult.getTotalrecord();
				               } 
				               if(s2.equals("CgTreatise")){
				            	   QueryResult<CgTreatise> queryResult = cgTreatiseDao.findByTeacherId(teacherId);
				            	   count1 = (int) queryResult.getTotalrecord();
				               } 
				               count2 +=count1;
				          }
				     }
//				String s3 =""+count2;
				  map.put(s1,String.valueOf(count2));
				}
			}
		}
		if(s.equals("postion")){
			list = teacherDao.findDistinctByPostion();
		for(int i=0;i<list.size();i++){
			String s1 = list.get(i);
			int count1 = 0;
			int count2 = 0;
			if(s1!=null&&!"".equals(s1)){
				List<Teacher> teacherlist = teacherDao.findByPostion(s1);
				if(teacherlist.size()>0){
					 Iterator<Teacher> it = teacherlist.iterator();   
				        while (it.hasNext())   
				        {   
				               Teacher teacher = it.next();
				               String teacherId = teacher.getTeacherId();
				               if(s2.equals("CgProject")){
				            	   QueryResult<CgProject> queryResult = cgProjectDao.findByTeacherId(teacherId);
				            	   count1 = (int)queryResult.getTotalrecord();
				               } 
				               if(s2.equals("CgConference")){
				            	   QueryResult<CgConference> queryResult = cgConferenceDao.findByTeacherId(teacherId);
				            	   count1 = (int)queryResult.getTotalrecord();
				               } 
				               if(s2.equals("CgInnovate")){
				            	   QueryResult<CgInnovate> queryResult = cgInnovateDao.findByTeacherId(teacherId);
				            	   count1 = (int)queryResult.getTotalrecord();
				               } 
				               if(s2.equals("CgPatent")){
				            	   QueryResult<CgPatent> queryResult = cgPatentDao.findByTeacherId(teacherId);
				            	   count1 = (int)queryResult.getTotalrecord();
				               } 
				               if(s2.equals("CgThesis")){
				            	   QueryResult<CgThesis> queryResult = cgThesisDao.findByTeacherId(teacherId);
				            	   count1 = (int)queryResult.getTotalrecord();
				               } 
				               if(s2.equals("CgTreatise")){
				            	   QueryResult<CgTreatise> queryResult = cgTreatiseDao.findByTeacherId(teacherId);
				            	   count1 = (int)queryResult.getTotalrecord();
				               } 
				               count2 +=count1;
				          }
				     }
//				String s3 =""+count2;
				  map.put(s1,String.valueOf(count2));
				}
			}
		}
		return map;
	}
	
	public Teacher findTeacherById(String id) {
		Teacher teacher=this.teacherDao.findById(id);
		if(teacher!=null){
			return teacher;
		}
		return null;
	}

	
	
}
